#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<assert.h>

void shellsort(int* a, int n)
{
	int gap = n;
	while (gap > 1)
	{
		gap = gap / 3 + 1;
		for (int i = 0; i < n - gap; i++)
		{
			int end = i;
			int temp = a[end + gap];
			if (temp < a[end + gap])
			{
				a[end + gap] = a[end];
				end = end - gap;
			}
			else
			{
				break;
			}
			a[end + gap] = temp;
		}
	}
}

void swap1(int* p, int* q)
{
	int temp = *p;
	*p = *q;
	*q = temp;
}
void selectsort(int* a, int n)
{
	int begin = 0;
	int end = n - 1;
	while (begin < end)
	{
		int maxi = a[begin];
		int mini = a[begin];
		for (int i = begin + 1; i <= end; i++)
		{
			if (a[i] < mini)
			{
				mini = a[begin];
			}
			if (a[i] > maxi)
			{
				maxi = a[end];
			}
			swap1(&a[begin], &mini);
			swap1(&a[end], &maxi);
			end--;
			begin++;
		}
	}

	for (int i = 0; i < 10; i++)
	{
		printf("%d ", a[i]);
	}
	printf("\n");
}
//void test02()
//{
//	int arr[10] = { 1,3,5,7,9,2,4,6,8,10 };
//	shellsort(arr, 10);
//}


void test02()
{
	int arr[10] = { 1,3,5,7,9,2,4,6,8,10 };
	selectsort(arr, 10);
}


int main()
{
	test02();
	return 0;
}